package com.laicunba.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.laicunba.pojo.FeedBackDO;
import com.laicunba.pojo.param.Page;
import com.laicunba.pojo.vo.FeedBackVO;
import com.laicunba.service.FeedBackService;
import com.laicunba.service.UserService;

@Service
public class FeedBackServiceImpl extends BaseServiceImpl implements FeedBackService {

	@Autowired
	private UserService userService;

	// 通过手机号模糊查询吐槽内容
	@Override
	public List<FeedBackVO> feedBackList(FeedBackVO feedBackVO) {
		List<FeedBackVO> feedBackVOList = queryDao.selectList("FEED_BACK.findFeedBackList", feedBackVO);
		return feedBackVOList;
	}

	@Override
	public List<FeedBackDO> findByUid(String uid, int limit) {
		Map map = new HashMap();
		map.put("uid", uid);
		map.put("limit", limit);
		return queryDao.selectList("FEED_BACK.findByUid", map);
	}

	@Override
	public List<Map<String, String>> findChatByUid(String uid, int limit) {
		Map map = new HashMap();
		map.put("uid", uid);
		map.put("limit", limit);
		return queryDao.selectList("FEED_BACK.findChatByUid", map);
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public List<Map<String, Object>> findFeedBackUserList(String status, Page page) {
		Map map = new HashMap();
		map.put("status", status);
		if(page != null && page.getPageIndex() > 0) {
			map.put("limit", page.getPageSize());
			map.put("offset", (page.getPageIndex() - 1) * page.getPageSize());
		}
		return queryDao.selectList("FEED_BACK.findFeedBackUserList", map);
	}
	
	@Override
	public int countUserFeedBackNoReply(String userId) {
		return queryDao.selectOne("FEED_BACK.countUserFeedBackNoReply", userId);
	}

	@Override
	public boolean updateFeedBackStatus(String userId) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("userId", userId);
		return updateDao.update("FEED_BACK.updateFeedBackStatus", map) >= 0;
	}

	@Override
	public List<Map<String, String>> findNewChatByUid(String userId, int limit) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userId", userId);
		map.put("limit", limit);
		return queryDao.selectList("FEED_BACK.findNewChatByUid", map);
	}
}
